<?php

namespace app\api\controller\app;

use app\admin\model\Banner;
use app\admin\model\City;
use app\admin\model\Org;
use app\admin\model\OrgIndexNotice;
use app\admin\model\OrgNotice;
use app\admin\model\Roomclean;
use app\admin\model\Shop;
use app\admin\model\Shopdevice;
use app\admin\model\Shopmno;
use app\admin\model\Shoporder;
use app\admin\model\Shoporderprofit;
use app\admin\model\Shoproom;
use app\admin\model\Shoproombook;
use app\admin\model\Userbalance;
use app\admin\model\Userorderprofit;
use app\admin\model\Usertuan;
use app\api\service\DeviceService;
use app\api\service\KmService;
use app\api\service\MtService;
use app\api\service\MtUtil;
use app\api\service\VbillService;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Http;
use fast\Random;
use think\Config;
use think\Validate;

/**
 */
class Ktv extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

    }

    public function getSongList()
    {

        $mac = $this->request->param('mac');
        $kmService = new KmService();
        $result = $kmService->getHotSongList($mac,"","",0);

        error_log("===getSongList==result=".json_encode($result));
        if($result['errno'] == 0){

            if(count($result['result']) == 0){
                $result = $kmService->searchSong($mac,"",0,"","","");
            }
            $this->success('',$result['result']);

        }else{
            $this->error($result['error']);

        }
    }

    public function getSingerTypeList()
    {
        $kmService = new KmService();
        $mac = $this->request->param('mac');
        $result = $kmService->getSingerTypeList($mac,"",1);
        if($result['errno'] == 0){
            $this->success('',$result['result']);

        }else{
            $this->error($result['error']);

        }
    }

    public function getSingerListByIndex()
    {
        $typeId = $this->request->param('typeId');
        $page = $this->request->param('page');
        $kmService = new KmService();
        $mac = $this->request->param('mac');

        $result = $kmService->getSingerListByIndex($mac,"",$page,$typeId);
        if($result['errno'] == 0){
            $this->success('',$result['result']);

        }else{
            $this->error($result['error']);

        }
    }

    public function searchSinger()
    {
        $keyword = $this->request->param('keyword');
        $mac = $this->request->param('mac');

        $kmService = new KmService();
        $result = $kmService->searchSinger($mac,"",0,$keyword);
        if($result['errno'] == 0){
            $this->success('',$result['result']);

        }else{
            $this->error($result['error']);

        }
    }

    public function getSongAllList()
    {

        $type = $this->request->param('type');
        $page = $this->request->param('page');
        $kmService = new KmService();
        $mac = $this->request->param('mac');

        if($type == 'hot'){
            $result = $kmService->getHotSongList($mac,"","",$page);
        }else{
            $result = $kmService->getSongPlaylist($mac,"",$page,$type);
        }
        if($result['errno'] == 0){
            $this->success('',$result['result']);

        }else{
            $this->error($result['error']);

        }
    }

    public function searchSong()
    {
        $page = $this->request->param('page');
        $keyword = $this->request->param('keyword');
        $singerid = $this->request->param('singerid');
        $songplaylistid = $this->request->param('songplaylistid');
        $mac = $this->request->param('mac');

        $kmService = new KmService();
        $result = $kmService->searchSong($mac,"",$page,$keyword,$singerid,$songplaylistid);
        if($result['errno'] == 0){
            $this->success('',$result['result']);
        }else{
            $this->error($result['error']);

        }
    }

    public function bindRoom()
    {

        $code = $this->request->param('code');
        $kmService = new KmService();
        $result = $kmService->bindRoom($code);

        error_log("====bindRoom=====".json_encode($result));
        if($result['errno'] == 0){

            $this->success('',$result['result']);
        }else{
            $this->error($result['error']);

        }
    }

    public function getEmojiTypeList()
    {
        $mac = $this->request->param('mac');

        $kmService = new KmService();
        $result = $kmService->getEmojiTypeList($mac);
        if($result['errno'] == 0){

            $this->success('',$result['result']);
        }else{
            $this->error($result['error']);

        }
    }

    public function getEmojiListByType()
    {
        $mac = $this->request->param('mac');
        $id = $this->request->param('id');
        $kmService = new KmService();
        $result = $kmService->getEmojiListByType($mac,$id);
        if($result['errno'] == 0){

            $this->success('',$result['result']);
        }else{
            $this->error($result['error']);

        }
    }

    public function sendEmoji()
    {
        $mac = $this->request->param('mac');
        $emojitype = $this->request->param('emojitype');
        $emojizipfolder = $this->request->param('emojizipfolder');
        $emojithumb = $this->request->param('emojithumb');
        $emojiname = $this->request->param('emojiname');
        $emojiimage = $this->request->param('emojiimage');


        $kmService = new KmService();
        $result = $kmService->sendEmoji($mac,$emojitype,$emojizipfolder,$emojithumb,$emojiimage,$emojiname);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }

    public function sendImageWithCensor()
    {
        $userId = $this->auth->getUser()['id'];
        $mac = $this->request->param('mac');
        $roomsendimage = $this->request->param('image');


        $kmSevice = new KmService();
        $result = $kmSevice->sendImageWithCensor($mac,$userId,$roomsendimage);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }


    public function sendTextWithCensor()
    {
        $userId = $this->auth->getUser()['id'];
        $mac = $this->request->param('mac');
        $text = $this->request->param('text');


        $kmSevice = new KmService();
        $result = $kmSevice->sendTextWithCensor($mac,$userId,$text);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }


    public function getYuList()
    {

        $list = ['唱得太棒了！再来一首！','天籁之音，震撼全场！','你是最亮的星，唱出你的光芒！',
            '声音美如画，耳朵要怀孕！','唱得我心都融化了！','舞台王者，非你莫属！','这声音绝了！全场嗨起来！',
            '唱得这么燃，是要炸场吗？','音乐因你更精彩！','开口跪！神仙嗓音！','唱得超有feel，爱了爱了！'
            ,'这高音绝了！牛！','耳朵享受，心灵震撼！','唱得这么深情，我哭了！','你就是今晚的MVP！',
            '声线太迷人，听不够啊！','全场尖叫！再来亿遍','这节奏感，绝了！','唱得我心潮澎湃！','音乐精灵，唱响全场！'];


        $key = array_rand($list);
        $value = $list[$key];
        $this->success('',$value);
    }

    public function songCtrl()
    {
        $mac = $this->request->param('mac');
        $songidlist = $this->request->param('songidlist');
        $songkplist = $this->request->param('songkplist');
        $roomsongaction = $this->request->param('roomsongaction');

        $kmService = new KmService();
        $result = $kmService->songCtrl($mac,$songidlist,$songkplist,$roomsongaction);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }

    public function getSelectedList()
    {
        $mac = $this->request->param('mac');
        $kmService = new KmService();
        $result = $kmService->getSelectedList($mac,"");
        error_log("=====getSelectedList===".json_encode($result));

        if($result['errno'] == 0){
            $this->success("发送成功",$result['result']['record']);
        }else{
            $this->error($result['error']);
        }
    }

    public function getSoundEffectList()
    {
        $mac = $this->request->param('mac');
        $kmService = new KmService();
        $result = $kmService->getSoundEffectList($mac);
        if($result['errno'] == 0){
            $this->success("发送成功",$result['result']);
        }else{
            if($result['error'] == '未支持'){

                $list = array();
                $obj = array();
                $obj['id'] = "1";
                $obj['name'] = "整蛊";
                $list[] = $obj;

                $obj = array();
                $obj['id'] = "2";
                $obj['name'] = "唱将";
                $list[] = $obj;

                $obj = array();
                $obj['id'] = "3";
                $obj['name'] = "和声";
                $list[] = $obj;


                $obj = array();
                $obj['id'] = "4";
                $obj['name'] = "搞怪";
                $list[] = $obj;

                $this->success('',$list);
            }else{
                $this->error($result['error']);
            }
        }
    }

    public function getLightCtrlType()
    {
        $mac = $this->request->param('mac');
        $kmService = new KmService();
        $result = $kmService->getLightCtrlType($mac);
        if($result['errno'] == 0){
            $this->success("",$result['result']);
        }else{
            $this->error($result['error']);
        }
    }

    public function lightCtrl()
    {
        $mac = $this->request->param('mac');
        $lightctrltype = $this->request->param('lightctrltype');
        $lightctrldata = $this->request->param('lightctrldata');

        $kmService = new KmService();
        $lightctrlsubtype = "";
        if($lightctrltype == 'v2'){
            $lightctrlsubtype = "lightid";
        }
        $result = $kmService->lightCtrl($mac,$lightctrltype,$lightctrlsubtype,$lightctrldata);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }

    public function soundEffectCtrl()
    {

        $mac = $this->request->param('mac');
        $id = $this->request->param('id');


        $kmService = new KmService();
        $result = $kmService->soundEffectCtrl($mac,$id);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }

    public function playCtrl()
    {

        $mac = $this->request->param('mac');
        $roomplayctrltype = $this->request->param('roomplayctrltype');


        $kmService = new KmService();
        $result = $kmService->playCtrl($mac,$roomplayctrltype);
        if($result['errno'] == 0){
            $this->success("发送成功");
        }else{
            $this->error($result['error']);
        }
    }

}
